package com.jdd.dao.vo;

import com.alibaba.fastjson.JSONObject;
import com.jdd.common.util.SnowFlakeUtil;
import com.jdd.dao.entity.SysDepartArea;
import com.jdd.dao.entity.TProject;
import com.jdd.modules.system.entity.SysUser;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author: LS
 * @Date: 2022 - 09 - 23 - 10:19
 * @Description: sysArea生成树辅助类
 * @version: 1.0
 */
@Data
public class SysAreaTreeModel {
    /*树形数据结构*/
    private String key;
    private String value;
    private String title;
    private boolean isLeaf;
    private String parentName;
    private List<SysAreaTreeModel> children = new ArrayList<>();

    /*是否是区域*/
    private Integer isArea;
    /*父节点id*/
    private String parentId;

    /**插槽*/
    private JSONObject slots;



    /*将区域对象转换为TSysAreaTreeModel对象*/
    public SysAreaTreeModel(SysDepartArea sysArea){
        this.key = sysArea.getId();
        this.value = sysArea.getId();
        this.title = sysArea.getName();
        this.parentId = sysArea.getParentId();
        this.isArea=1;
        this.slots = new JSONObject();
        this.slots.put("icon","apartment");
    }
    public SysAreaTreeModel(TProject tProject){
        this.key = tProject.getId();
        this.value = tProject.getId();
        this.title = tProject.getName();
        this.parentId = tProject.getSysAreaId();
        this.isArea = 0;
        this.slots = new JSONObject();
        this.slots.put("icon","home");
    }

    private SysAreaTreeModel(SysUser sysUser,String parentId)
    {

        this.key= SnowFlakeUtil.getId();
        this.value = sysUser.getId();
        this.title = sysUser.getUsername();
        this.parentId = parentId;
        this.isArea = 2;
        this.slots = new JSONObject();
        this.slots.put("icon","user");
    }

    public void setBindUsers(List<SysUser> bindUser){
        for(SysUser sysUser:bindUser)
        {
            this.children.add(new SysAreaTreeModel(sysUser,this.key));
        }
    }

}
